﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AIC_Notification
{
    class TaskStatusReport: FormatedReport
    {
        public IList<SOF_Application> Applications;

        public override string InnerTableHeader()
        {
            string tableHeader = "";

            tableHeader += "<tr>";

            // Add Student Name column
            tableHeader += String.Format("<th style=\"font-size: {0}px; \">Students</th>", 14);

            // Add Special List column
            tableHeader += String.Format("<th style=\"font-size: {0}px;\">{1}</th>", "School List", 14);
            tableHeader += String.Format("<th style=\"font-size: {0}px;\">{1}</th>", "Rec Letters", 14);
            tableHeader += String.Format("<th style=\"font-size: {0}px;\">{1}</th>", "App Material Mailing", 14);
            tableHeader += String.Format("<th style=\"font-size: {0}px;\">{1}</th>", "Sending Score", 14);
            tableHeader += String.Format("<th style=\"font-size: {0}px;\">{1}</th>", "App Status Check", 14);
            tableHeader += String.Format("<th style=\"font-size: {0}px;\">{1}</th>", "App Forms", 14);
            tableHeader += String.Format("<th style=\"font-size: {0}px;\">{1}</th>", "Finance", 14);
            tableHeader += String.Format("<th style=\"font-size: {0}px;\">{1}</th>", "Visa", 14);

            tableHeader += "</tr>";

            return tableHeader;
        }

        public override string GenerateInnerTable()
        {
            string tableBody = "";

            if (Applications.Count > 0)
            {
                /*
                                foreach (var application in Applications)
                                {
                                    // Insert student name here
                                    foreach (var worklist in application.Schools)
                                    {
                                        foreach (var work in worklist.Tasks)
                                        {
                                            // Figure out x/x for each task list
                                            foreach (var task in work.TaskLists)
                                            {
                                                int TotalTask = task.Items.Count();
                                                int CompleteTask = 0;

                                                foreach (var item in task.Items)
                                                    CompleteTask += item.State ? 1 : 0;
                                            }
                                        }
                                    }
                                }
                */
            }

            // Add Header


            return tableBody;
        }
        
        public override void SendReportAsEmail()
        {
            foreach (var _teacher in TeacherDB.Teachers)
            {
                string HTMLBody;

                // Only for AC with one student or more
                if ((_teacher.Type.Equals("Academic Consultant") || _teacher.Type.Equals("Both")) && _teacher.Students.Count > 0)
                {
                    Applications = _teacher.Students;
                    HeaderInformation = _teacher.Name;

                    FileName = String.Format("{0}-{1}-{2:yyyyMMdd-HHmmss}.htm", ReportTitle, _teacher.Name, Global.Now());
                    Global.SysUtil.Log("Generating Report: " + FileName);

                    HTMLBody = GetHTMLBody();

                    // Save Report to File
                    SaveReportToFile(FileName, HTMLBody);

                    // Send Report E-mail
                    toRecipients.Clear();
                    ccRecipients.Clear();

                    // toRecipients.Add(_teacher.Email);
                    SubjectID = _teacher.Name;

                    // Copy Admin
                    string[] SystemAdmins = TeacherDB.GetSystemAdmin();
                    foreach (var SystemAdmin in SystemAdmins)
                        ccRecipients.Add(SystemAdmin);

                    Global.SysUtil.SendHTML(toRecipients, ccRecipients, GetSubject(), HTMLBody);
                }
            }
        }

    }
}
